<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */

$intBT = (int)$_data["Bet_Type"];
$intGID = (int)$_data["GambleID"];
$intNum = (int)$_data["intNumber"];
$flOdds = (float)$_data["Odds"];
$isSpecial = (int)$_data["isSpecial"];
$intSpecialNumType = (int)$_data["SpecialNumType"];

if($intBT < 1 || $intGID < 1 || $intLID < 1){
	$GLOBALS["errormessage"] = "Data Error!!";
	$GLOBALS["errorhidden"] = "\nBetType:".$intBT."\nGambleID:".$intGID."\nLottoID:".$intLID."\nLine:".__LINE__."\nPage:".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}

$flOdds = ConvertOdds($intLType, $intBT, $flOdds);
$intAN = $_arrGLineNumToApointNum[$intLID][$intBT][$intNum];
if($intAN == null)$intAN = 0;

include_once(__Common_Path."/gambletype/GambleType1_".$intLID.".inc.php");
$A_AllOdds = $_arrGambleTypeAllOdds[$intBT][$intAN];
include_once(__Common_Path."/gambletype/GambleType".$_data["GameType"]."_".$intLID.".inc.php");
$preAllOdds = $_arrGambleTypeAllOdds[$intBT][$intAN];
$flOdds -= ($preAllOdds - $A_AllOdds)/2;

if($flOdds < 0)$flOdds = 0;
if($_arrBetParam[$intBT][$intAN]["maxOdds"] < $flOdds)$flOdds = $_arrBetParam[$intBT][$intAN]["maxOdds"];

$intNumber = 0;

PMA_mysql_query("BEGIN", $_ConnMaster);
switch($intBT){
	case 52:
	case 53:
	case 55:
	case 56:
	case 58:
	case 59:
	case 62:
	case 63:
	case 84:
	case 85:
	case 86:
		$intNumber = (int)$intNum;
		$intNumber2 = ($intNumber % 10 == 1)?($intNumber - 1):($intNumber + 1);
		//輸入單分或大賠率
		$OtherOdds = $A_AllOdds - $flOdds;
		$OtherOdds = ConvertOdds($intLType, $intBT, $OtherOdds);
		if(!$intOID = InsertBetTypeOdds($intGID, $intLID, $intBT, $intNumber, $flOdds, 0, $_SESSION["Admin_Info"] -> Account)){
			@PMA_mysql_query("ROLLBACK", $_ConnMaster);
			ErrMsgOutputHTML("Error", "", 1);
		}
		if(!UpdateTodayGame($intGID, $intLID, $intBT, $intNumber, $intOID, $flOdds, ", tolJumpStake = 0")){
			@PMA_mysql_query("ROLLBACK", $_ConnMaster);
			ErrMsgOutputHTML("Error", "", 1);
		}

		//輸入雙分或小盤賠率
		if(!$intOID2 = InsertBetTypeOdds($intGID, $intLID, $intBT, $intNumber2, $OtherOdds, 0, $_SESSION["Admin_Info"] -> Account)){
			@PMA_mysql_query("ROLLBACK", $_ConnMaster);
			ErrMsgOutputHTML("Error", "", 1);
		}
		if(!UpdateTodayGame($intGID, $intLID, $intBT, $intNumber2, $intOID2, $OtherOdds, ", tolJumpStake = 0")){
			@PMA_mysql_query("ROLLBACK", $_ConnMaster);
			ErrMsgOutputHTML("Error", "", 1);
		}
		break;

	default:
		if(!$intOID = InsertBetTypeOdds($intGID, $intLID, $intBT, $intNum, $flOdds, 0, $_SESSION["Admin_Info"] -> Account)){
			@PMA_mysql_query("ROLLBACK", $_ConnMaster);
			ErrMsgOutputHTML("Error", "", 1);
		}
		if(!UpdateTodayGame($intGID, $intLID, $intBT, $intNum, $intOID, $flOdds, ", tolJumpStake = 0")){
			@PMA_mysql_query("ROLLBACK", $_ConnMaster);
			ErrMsgOutputHTML("Error", "", 1);
		}
		break;
}
@PMA_mysql_query("COMMIT", $_ConnMaster);
//產生 TodayGame File
if(!MakeTodayGameFile($intLID, $intBT))ErrMsgOutputHTML("Error", "", 1);

$strLog = "樂透種類：".$intLID."\n";
$strLog .= "操盤序號：".$intGID."\n";
$strLog .= "下注種類：".$intBT."\n";
$strLog .= "賠率序號：".$intOID."：".$intOID2."\n";
$strLog .= "賠率：".$flOdds."：".$OtherOdds."\n";
$strLog .= "號碼：".$intNum."\n";
AddData_Log($_SESSION["Admin_Info"] -> ID, "更改賠率", $strLog);

if($intBT == 92 || $intBT == 93){
	/*=================================================================*/
	header("Cache-Control: no-store, no-cache, must-revalidate");	  // HTTP/1.1
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");															  // HTTP/1.0
	?><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<script language="JavaScript">
	<!--
	parent.ChangeBet(<?php print $intBT;?>);
	//-->
	</script><?php
	exit();
}
?>